package com.uenpay.im.ui.old.activity.area;

import com.qiyunxin.android.http.listener.OnHttpRequestTextListener;
import com.qiyunxin.android.http.net.HttpInvokeItem;
import com.qiyunxin.android.http.net.HttpRequestAsyncTaskQueue;
import com.qiyunxin.android.http.net.HttpRequestType;
import com.qiyunxin.android.http.net.HttpTextAsyncTask;

import java.util.ArrayList;

/**
 * @author SL
 * @created 2016-1-28 下午3:10:29
 * @copyRight http://www.qiyunxin.com
 * @function TODO
 */
public class AreaHandle {

	public interface IGetAreaResultListener {
		void onGetAreaResult(int status, String msg,
									  ArrayList<AreaEntity> arrayList);
	}

	public void getArea(String level, String peare,
			final IGetAreaResultListener mIGetAreaResultListener) {
		GetAreaInvokeItem item = new GetAreaInvokeItem(level, peare);
		HttpRequestAsyncTaskQueue
				.getInstance()
				.AddTask(
						new HttpTextAsyncTask(item)
								.SetRequestType(HttpRequestType.SERVER_FAIL_AND_CACHE),
						new OnHttpRequestTextListener() {

							@Override
							public void OnFail(boolean isCache, String reason) {
								if (mIGetAreaResultListener != null) {
									mIGetAreaResultListener.onGetAreaResult(-1,
											reason, null);
								}
							}

							@Override
							public void OnProgress(long total_bytes,
									long downloaded_bytes) {
							}

							@Override
							public void OnSuccess(HttpInvokeItem item,
									boolean isCache, String cacheFilePath) {
								GetAreaInvokeItem.GetAreaInvokeItemResult result = ((GetAreaInvokeItem) item)
										.getOutput();
								if (result != null) {
									if (mIGetAreaResultListener != null) {
										mIGetAreaResultListener
												.onGetAreaResult(result.status,
														result.msg,
														result.areaEntities);
									}
								} else {
									if (mIGetAreaResultListener != null) {
										mIGetAreaResultListener
												.onGetAreaResult(-1, "", null);
									}
								}
							}
						});

	}
}
